Option Strict On

Imports System.Drawing
Imports System.Windows.Forms

Namespace xpComponent.Form
    Public Class xpDateTimePicker
        Inherits System.Windows.Forms.DateTimePicker
        Implements xpComponent.Form.IDisabled

        Private mclrBackColorDisabled As System.Drawing.Color = System.Drawing.Color.Gainsboro
        Private mclrForeColorDisabled As System.Drawing.Color = System.Drawing.SystemColors.ControlText

        Public Property BackColorDisabled() As System.Drawing.Color Implements xpComponent.Form.IDisabled.BackColorDisabled
            Get
                Return mclrBackColorDisabled
            End Get
            Set(ByVal Value As System.Drawing.Color)
                mclrBackColorDisabled = Value
            End Set
        End Property

        Public Property ForeColorDisabled() As System.Drawing.Color Implements xpComponent.Form.IDisabled.ForeColorDisabled
            Get
                Return mclrForeColorDisabled
            End Get
            Set(ByVal Value As System.Drawing.Color)
                mclrForeColorDisabled = Value
            End Set
        End Property

        Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
            MyBase.OnEnabledChanged(e)
            If Not Me.Enabled Then
                Me.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, True)
            Else
                Me.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, False)
            End If
            Me.Invalidate()
        End Sub

        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
            Dim TextBrush As System.Drawing.SolidBrush

            'Set user selected backcolor when disabled
            If Me.Enabled Then
                TextBrush = New System.Drawing.SolidBrush(Me.ForeColor)
            Else
                TextBrush = New System.Drawing.SolidBrush(Me.ForeColorDisabled)
                Dim BackBrush As New System.Drawing.SolidBrush(Me.BackColorDisabled)
                e.Graphics.FillRectangle(BackBrush, ClientRectangle)
            End If

            'Paint text
            e.Graphics.DrawString(Me.Text, Me.Font, TextBrush, 0.0F, 0.0F)
        End Sub
    End Class
End Namespace